package week_home_work02;

import java.util.Scanner;

/**
 * @author zdl
 * @date 2024/11/23
 */
public class Demo51 {
    public static void main(String[] args) {
        //设计一个程序，输入一个正整数，输出该整数的各个数字之和。
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入一个正整数:");
        int num = sc.nextInt();
        int yuanNum = num;
        int sum = 0;
        while (num != 0) {
            int lastNum = num % 10;
            sum += lastNum;
            num /= 10;
        }
        System.out.println(yuanNum + "各位数之和为:" + sum);
    }
}
